﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8" />
    <title>方向条件-按照岗位计算</title>
    <!-- 于庆海 -->
    <link href="../../Comm/Style/Table0.css" rel="stylesheet" type="text/css" />
    <script src="../../Scripts/bootstrap/js/jquery.min.js" type="text/javascript"></script>
    <script src="../../Scripts/QueryString.js" type="text/javascript"></script>
    
    <!-- 引用通用的js文件. -->
    <script src="../../Scripts/config.js" type="text/javascript"></script>
    <script src="../../Comm/Gener.js" type="text/javascript"></script>
    <script src="../../Comm/JScript.js" type="text/javascript"></script>
    <script src="../CCFlowEnum.js" type="text/javascript"></script>
    <script type="text/javascript" language="javascript">
        var selectType =1;
        //页面启动函数.
        $(function () {

            $("#Msg").html("正在加载,请稍后......");

            InitPage();

            $("#Msg").html("");
        });
        //初始化数据.
        function InitPage() {

            //获取URL参数
            var nodeID = GetQueryString("FK_Node");
            var orgNo = GetQueryString("OrgNo");
            var emps = GetQueryString("emps");
            selectType = GetQueryString("SelectType");
            var CheckStations = emps.split(",");
            //岗位类型集合
            var StationTypes;
            //岗位集合
            var Stations;

            ////根据用户的信息，判断是否启用那个设置工具。
            var user = new WebUser();

            /*调用通用的.*/
            if (orgNo == null || orgNo == "") {
                StationTypes = new Entities("BP.GPM.StationTypes");
                StationTypes.RetrieveAll();
                Stations = new Entities("BP.GPM.Stations");
                Stations.RetrieveAll();
               
             /*调用集团模式的.*/
            } else {
                Stations = new Entities("BP.GPM.Stations");
                Stations.Retrieve("OrgNo", orgNo);
                //查询出来数据.	       
                var sql = "select No,Name from port_StationType where No in (select Fk_StationType from Port_Station where OrgNo =" + orgNo + ")";
                //获得要增加的流程集合.
                StationTypes = DBAccess.RunSQLReturnTable(sql);
            }
            //初始化岗位Table显示
            InitStationTable(StationTypes, Stations);

            //获取已指定操作员的岗位条件
            for (i = 0, len = CheckStations.length; i < len; i++) {
                if (CheckStations[i] == "")
                    continue;

                var stationObject = document.getElementById("emp_CB_" + CheckStations[i]);
                if (stationObject != null)
                    stationObject.checked = true;
            }
        }

        //初始化岗位列表TABLE
        function InitStationTable(stationTypes, stations) {
            for (var i = 0, len = stationTypes.length; i < len; i++) {
                var typeno = stationTypes[i].No;

                var curstas = [];
                var ids = "";
                for (var j = 0, jlen = stations.length; j < jlen; j++) {
                    if (stations[j].FK_StationType == typeno) {
                        curstas.push(stations[j]);
                        ids += "CB_" + stations[j].No + ",";
                    }
                }

                var title = "<tr><td colspan='3' class='GroupTitle'><input id='CB_type_" + typeno + "' type='checkbox' name='CB_type_" + typeno + "' onclick=\"SetSelected(this,'" + ids + "')\"/><label for='CB_type_" + typeno + "' >" + stationTypes[i].Name + "</label></td></tr>";
                $("#t1").append(title);

                for (var k = 0, klen = curstas.length; k < klen; k++) {
                    var td = "<td><input type='checkbox' id='emp_CB_" + curstas[k].No + "' name='emp_CB_" + curstas[k].No + "'/><label for='emp_CB_" + curstas[k].No + "' id="+curstas[k].No+">" + curstas[k].Name + "</label></td>";
                    if (k % 3 == 0) {
                        $("#t1").append("<tr></tr>");
                    }

                    $("#t1 tr:last").append(td);
                }
            }
        }

        function Save() {
            var emps = ",";
            var html = "&nbsp;&nbsp;";
            var i = 0;
            var data = new Array();
            $("input[type='checkbox']").each(function () {
                if (this.checked && this.name.indexOf("emp_CB_") == 0) {
                    var id = this.name.replace("emp_CB_", "")
                    emps += id + ",";
                    html += document.getElementById(id).innerHTML+ "&nbsp;&nbsp;";
                    i++;
                   
                }
            });
            data[0] = emps;
            data[1] = html;
            data[2] = i;
            data[3] = selectType;
            window.parent.window.getChidrenValue(data);

        }
     </script>

    <style type="text/css">
        ul .cond li
        {
            display: none;
            line-height: 50px;
        }
        
        ul .cond li .active
        {
            display: block;
        }
        
        select
        {
            display: inline-block;
            width: 200px;
        }
        
        .btn
        {
            display:inline-block;
            height:20px;
            background-color:#0099ff;
            text-decoration:none;
            color:#fff;
            padding:3px 15px;
            margin:10px 10px;
        }
        .lbls span
        {
            width:80px;
         }
    </style>
</head>
<body>
    <input type="button" value='保存' onclick='Save();' id='Save' />
    <div style="max-height:600px;overflow:auto;">
            <table id="t1" class="Table" cellspacing="1" cellpadding="1" border="1" style="width: 100%">
            </table>
    </div>
    <div id="Msg"></div>
</body>
</html>
